package com.yanqu.road.server.manger;

import com.yanqu.road.logic.config.ServerConfig;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manger.plugin.ManagerReloadListener;
import com.yanqu.road.utils.ConfigHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ServerConfigMgr extends TempMgr {

	private static Logger logger = LogManager.getLogger(ServerConfigMgr.class.getName());

	private static ManagerReloadListener managerReloadListener;

	@Override
	public boolean stop() {
		return false;
	}

	@Override
	public boolean init() throws Exception {
		return reload();
	}

	@Override
	public boolean reloadData() {
		long serverId = Long.parseLong(ConfigHelper.getValue("serverId"));
		ServerConfig.reloadServerConfig(serverId);
		notifyReload();
		return true;
	}

	@Override
	public boolean reloadConfig() throws Exception {
		return true;
	}

	public static void addReloadListener(ManagerReloadListener reloadListener){
		managerReloadListener = reloadListener;
	}

	private static void notifyReload(){
		if(null != managerReloadListener){
			managerReloadListener.notifyReload();
		}
	}
}
